package com.conn3cted.phrasebook.web;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.conn3cted.phrasebook.domain.Person;

@RequestMapping("/login")
@Controller
public class LoginController extends BaseController{

	@RequestMapping(method = RequestMethod.POST)
	public String onSubmit(@RequestParam("username") String username,
			@RequestParam("password") String password, Model uiModel) {

		if (Person.findPerson(username, password) != null) {

			uiModel.addAttribute("person",
					Person.findPerson(username, password));
			return "home";
		}

		uiModel.addAttribute("error", "error_login");
		return "index";

	}

	@RequestMapping("/signOut")
	public String signOut(Model uiModel) {
		return "index";
	}
}
